home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / flock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-16  |  2.4 KB  |  93 lines

  1. /*
  2.  * Copyright (c) 1989 Mark Davies
  3.  * Copyright (c) 1990 Andy Linton
  4.  * Copyright (c) 1990 Victoria University of Wellington.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms are permitted provided
  8.  * that: (1) source distributions retain this entire copyright notice and
  9.  * comment, and (2) distributions including binaries display the following
  10.  * acknowledgement:  ``This product includes software developed by the
  11.  * Victoria University of Wellington, New Zealand and its contributors''
  12.  * in the documentation or other materials provided with the distribution
  13.  * and in all advertising materials mentioning features or use of this
  14.  * software.
  15.  * Neither the name of the University nor the names of its contributors may
  16.  * be used to endorse or promote products derived from this software without
  17.  * specific prior written permission.
  18.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  19.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21.  */
  22.  
  23. #include "sendmail.h"
  24. #include <errno.h>
  25.  
  26. #ifndef    lint
  27. static char sccsid[] = "%W%";
  28. static char  rcsid[] = "@(#)$Id: flock.c,v 1.3 1991/06/21 12:48:43 paul Exp $";
  29. #endif
  30.   
  31. #if defined(FCNTL_FLOCK) && defined(LOCKF_FLOCK)
  32.     MULTIPLE_FLOCK_REPLACEMENTS_DEFINED
  33. #endif /* FCNTL_FLOCK && LOCKF_FLOCK */
  34.  
  35. #ifdef FCNTL_FLOCK
  36.  
  37. int
  38. flock(fd, operation)
  39. int fd, operation;
  40. {
  41.     int op, ret;
  42.     struct flock arg;
  43.     extern int errno;
  44. # ifdef __STDC__
  45.     extern int fcntl(int, int, ...);
  46. # else /* !__STDC__ */
  47.     extern int fcntl();
  48. # endif /* __STDC__ */
  49.  
  50.     op = (LOCK_NB & operation) ? F_SETLK : F_SETLKW;
  51.     
  52.     arg.l_type = (LOCK_EX & operation) ? F_WRLCK :
  53.         (LOCK_SH & operation) ? F_RDLCK : F_UNLCK;
  54.     arg.l_whence = 0;
  55.     arg.l_start = 0;
  56.     arg.l_len = 0;
  57.     arg.l_pid = 0;
  58.     
  59.     if ((ret = fcntl(fd, op, &arg)) == -1) {
  60.         if (errno == EACCES || errno == EAGAIN)
  61.             errno = EWOULDBLOCK;
  62.     }
  63.     return (ret);
  64. }
  65.  
  66. #endif /* FCNTL_FLOCK */
  67. #ifdef LOCKF_FLOCK
  68.  
  69. int
  70. flock(fd, operation)
  71. int fd, operation;
  72. {
  73.     int op, ret;
  74.     extern int errno;
  75. #ifdef __STDC__
  76.     extern int lockf(int, int, long);
  77. #else /* !__STDC__ */
  78.     extern int lockf();
  79. #endif /* __STDC__ */
  80.  
  81.     op = (LOCK_UN & operation) ? F_ULOCK :
  82.       (LOCK_NB & operation) ? F_TLOCK : F_LOCK;
  83.  
  84.     if ((ret = lockf(fd, op, 0L)) == -1) {
  85.         if (errno == EACCES || errno == EAGAIN)
  86.             errno = EWOULDBLOCK;
  87.     }
  88.  
  89.     return (ret);
  90. }
  91.  
  92. #endif /* LOCKF_FLOCK */
  93.